//
//  SEGMenuChildListViewController.m
//  SEGUhomeStandard
//
//  Created by 刘山 on 2018/5/9.
//  Copyright © 2018年 刘山. All rights reserved.
//

#import "SEGMenuChildListViewController.h"
#import "SEGMenulistRCView.h"

@interface SEGMenuChildListViewController ()
@property (nonatomic, strong) UIScrollView *backGroundView;
@end

@implementation SEGMenuChildListViewController{
    SEGMenulistRCView *varMenulistRCView;
}
#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initNotification];
    [self initSubView];
}

#pragma mark - init
- (void)initNotification {
    //新红点逻辑监听 4.4.0新增
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addRedDot:) name:SEGAddReddotNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hiddenRedDot:) name:SEGHiddenRedDotNotification object:nil];
}

- (void)initSubView {
    self.view.backgroundColor = kColor_bg;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    [self.view addSubview:self.backGroundView];
    self.backGroundView.frame = self.view.bounds;
    [self segInitView];
}

- (void)segInitView {
    if(!self.dataSource ||self.dataSource.count <= 0 ) return;
    // 控件内容布局计算
    SEGMenulistRCViewLayout *layout = [[SEGMenulistRCViewLayout alloc]initWithData:self.dataSource type:SEGEnumShowTypeThreeColumsSpread];
    // 内容布局填充到视图
    varMenulistRCView = [[SEGMenulistRCView alloc]initWithFrame:CGRectZero];
    [varMenulistRCView setWithLayout:layout];
    [self.backGroundView addSubview:varMenulistRCView];
    self.backGroundView.contentSize = CGSizeMake(LYScreenWidth(), layout.totalHeight);
}

#pragma mark - send request

#pragma mark - custom delegate

#pragma mark - system delegate

#pragma mark - event response

#pragma mark - private methods
- (void)addRedDot:(NSNotification *)notification {
    if (notification.object) {
        NSArray *ids = notification.object;
        if (ids && [ids isKindOfClass:[NSArray class]]) {
            dispatch_async(dispatch_get_main_queue(), ^{
               [varMenulistRCView segRedShow:ids];
            });
        }
    }
}

- (void)hiddenRedDot:(NSNotification *)notification {
    if (notification.object) {
        NSArray *ids = notification.object;
        if (ids && [ids isKindOfClass:[NSArray class]]) {
            dispatch_async(dispatch_get_main_queue(), ^{
               [varMenulistRCView segRedHidden:ids];
            });
        }
    }
}
#pragma mark - setter and getter
- (UIScrollView *)backGroundView {
    if (!_backGroundView) {
        _backGroundView = [[UIScrollView alloc]init];
        _backGroundView.backgroundColor = [UIColor whiteColor];
        _backGroundView.contentSize = CGSizeMake(0, 0);
        _backGroundView.showsVerticalScrollIndicator = NO;
        _backGroundView.showsHorizontalScrollIndicator = NO;
    }
    return _backGroundView;
}


@end
